package com.medical.system.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.medical.system.common.Result;
import com.medical.system.common.ResultCodeEnum;
import com.medical.system.model.Doctor;
import com.medical.system.service.DoctorService;
import com.medical.system.vo.SysDoctorVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "医生信息控制器")
@RestController
@RequestMapping("admin/system/doctor")
public class DoctorController {

    @Autowired
    private DoctorService doctorService;

    @ApiOperation("分页和条件查询")
    @GetMapping("/{page}/{limit}")
    public Result selectUserPageByVo(@PathVariable Long page,
                                     @PathVariable Long limit,
                                     SysDoctorVo sysDoctorVo) {
        IPage<Doctor> doctorPage = new Page<>(page, limit);
        return this.doctorService.selectPage(doctorPage, sysDoctorVo);
    }

    @ApiOperation("新增医生")
    @PostMapping("/insertDoctor")
    public Result insertDoctor(@RequestBody Doctor doctor) {
        if (doctor == null || ("".equals(doctor.getName()) && "".equals(doctor.getPhone()))) {
            return Result.build(null, ResultCodeEnum.ILLEGAL_REQUEST);
        }
        return this.doctorService.insertDoctor(doctor);
    }

    @ApiOperation("修改医生信息")
    @PostMapping("/updateDoctor")
    public Result updateDoctor(@RequestBody Doctor doctor) {
        return this.doctorService.updateDoctor(doctor);
    }

    @ApiOperation("删除医生信息")
    @DeleteMapping("deleteDoctor/{id}")
    public Result deleteDoctor(@PathVariable Integer id) {
        if (id == null) {
            return Result.build(null, ResultCodeEnum.ILLEGAL_REQUEST);
        }
        return this.doctorService.deleteDoctor(id);
    }

    @ApiOperation("根据ID查询医生信息")
    @GetMapping("/selectDoctorById/{id}")
    public Result selectDoctorById(@PathVariable Integer id) {
        if (id == null) {
            return Result.build(null, ResultCodeEnum.ILLEGAL_REQUEST);
        }
        return this.doctorService.selectDoctorById(id);
    }

    @ApiOperation("修改医生状态")
    @GetMapping("upStatusDoctor/{id}/{status}")
    public Result upStatusDoctor(@PathVariable Integer id, @PathVariable Integer status) {
        return this.doctorService.upStatusDoctor(id, status);
    }
}
